﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.NoticeUI
{
    public partial class ViewNotice : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetAllNotices();
            }
            if (Convert.ToInt32(Request.QueryString["id"])>0)
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                GetNotice(id);
            }

        }

        private void GetNotice(int id)
        {
            NoticeManager manager = new NoticeManager();
            Notice notice = new Notice();
            notice = manager.GetNotice(id);
            noticeTitleLabel.Text = notice.Subject;
            lblNoticeBy.Text = notice.NoticeBy;
            lblDate.Text = notice.Date;
            lblSummary.Text = notice.Summary;
            imgNotice.ImageUrl = notice.NoticeImage;
        }

        private void GetAllNotices()
        {
            NoticeManager manager = new NoticeManager();
            NoticeGridView.DataSource = manager.GetAllNotices();
            NoticeGridView.DataBind();
            int i = 0;
            foreach (Notice notice in manager.GetAllNotices())
            {
                if (i == 0)
                {
                    noticeTitleLabel.Text = notice.Subject;
                    lblNoticeBy.Text = notice.NoticeBy;
                    lblDate.Text = notice.Date;
                    lblSummary.Text = notice.Summary;
                    imgNotice.ImageUrl = notice.NoticeImage;
                }
                i++;
            }
        }


        protected void NoticeGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            NoticeGridView.PageIndex = e.NewPageIndex;
            GetAllNotices();
        }

    }
}